<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<p>这是SSE内容:<span id="content"></span></p>
<!-- 创建一个sse连接 http://localhost:8888/subscribe/{{id}}-->
<script>
    var date = "";
    window.onload = function () {
        date = new Date().toLocaleTimeString();
    }
    var source = new EventSource("http://localhost:8888/subscribe/1");
    try {
        source.onmessage = function (event) {
            document.getElementById("content").innerHTML += event.data;
            console.log("xinxi:");
            console.log(event);

        };
    } catch (e) {
        // 捕获异常
            // 输出当前时间
            console.log(date);
            console.log(new Date().toLocaleTimeString());
    }
</script>
</body>
</html>